
//index.js

//请求网络数据，并解析

var app = getApp()

Page({
  data: {
    imgSrc: '',
  },
  uploadfile: function () {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        var tempFilePaths = res.tempFilePaths
        that.setData({
          imgSrc: tempFilePaths[0]
        })
        var tempFilePaths = res.tempFilePaths
        wx.uploadFile({
          url: 'https://testsfy.applinzi.com/upload.php', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'file',
          success: function (res) {
            var data = res.data
            console.log(res.data);
            //do something
          }
        })
      }
    })
  },
  downfile: function () {
    var that = this;
    wx.downloadFile({
      url: 'https://testsfy.applinzi.com/2.docx', //仅为示例，并非真实的资源
      success(res) {
        // 只要服务器有响应数据，就会把响应内容写入文件并进入 success 回调，业务需要自行判断是否下载到了想要的内容
        var filepath = res.tempFilePath;
        console.log(filepath);
        //that.setData({
        //imgSrc:res.tempFilePath,
        //});
        wx.openDocument({
          filePath: filepath,
          filetype: 'docx',
          success: function (res) {
            console.log('打开文档成功')
          },
          fail: function (res) {
            console.log('打开文档失败')
          },
          complete: function (res) {
            console.log(res);
          }

        })
      }
    })
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  requstmq:function(){
    wx.redirectTo({
      url: '../index/index'
    })
  }
})
  




